package com.java.base.exercise;

import java.util.*;

/**
 * @Author RenPu
 * @Date 2022/7/13 8:46
 * @Version 1.0
 * @Description:
 **/
public class TestCollections {

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>(Arrays.asList("1", "4","2","6","0"));

        Collections.sort(list);  //正序排序的写法
        System.out.println("正序排序的结果：{====正+++++序=====}"+list);

        //倒叙排序的写法
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String s, String t1) {
                return t1.compareTo(s);
            }
        });
        System.out.println("倒序排序的结果：{====倒+++++序=====}"+list);

        int count=(0 + 10) >>> 1;

        System.out.println("mid 中间值 ：{======}"+count);

        int indexId = Collections.binarySearch(list, "2");
        System.out.println("二分查找法获取值对应的下标值：{===   ==}"+indexId);


        //洗牌算法抽奖、摇号、洗牌等各个场景中
        //方式一
        Collections.shuffle(list);
        System.out.println("洗牌算法后的集合数据排列,方式一："+list);

        //方式二
        Collections.shuffle(list, new Random(100));
        System.out.println("洗牌算法后的集合数据排列,方式二："+list);


        List<String> list1 = new ArrayList<>(Arrays.asList("1", "2","3","4","5"));

        //旋转算法：
        // int 代表把几位值，进行旋转
        Collections.rotate(list1,2);
        System.out.println("旋转算法处理后的结果：{}"+list1);


        //获取最大值以及最小值
        Integer max = Collections.max(Arrays.asList(6, 1, 9, 6, 10, 25, 8));
        Integer min = Collections.min(Arrays.asList(6, 1, 9, 6, 10, 25, 8));
        System.out.println("最大值为：{==}"+max+"最小值为：{==}"+min);


        //元素替换操作
        List<String> list2 = new ArrayList<>(Arrays.asList("1", "2","3","4","5"));

        Collections.replaceAll(list2,"4","886");
        System.out.println("集合被替换后的数据样式：{====}"+list2);


        //创建线程安全的list，map集合
        List<String> list3 = Collections.synchronizedList(new ArrayList<String>());
        Map<String, String> map = Collections.synchronizedMap(new HashMap<String, String>());





    }


}
